package com.yonyou.pmclouds.workflow.service;

import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.workflow.service.rmiitf.IProcessService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import yonyou.bpm.rest.*;
import yonyou.bpm.rest.param.BaseParam;

/**
 *  获取业务流程服务
 *  @author zhangzhonghao
 *
 */

@Service
public class ProcessService implements IProcessService {

    @Value("${bpmrest.server}")
    private String serverUrl;
    @Value("${bpmrest.tenant}")
    private String tenant;
    @Value("${bpmrest.token}")
    private String token;
    @Value("${bpmrest.callbackurl}")
    private String callbackurl;
    @Value("${bpmrest.designerUrl}")
    private String designerUrl;

    @Override
    public BpmRest bpmRestServices(String userId, String tenantId) throws BusinessException {
        if (StringUtils.isEmpty(userId)) {
            throw new BusinessException("获取BpmRest时传入的userId是空");
        }
        BaseParam baseParam = new BaseParam();
        baseParam.setOperatorID(userId);
        // U审rest服务地址：http://ys.yyuap.com/ubpm-web-rest
        baseParam.setServer(serverUrl);
        // 租户code
        baseParam.setTenant(tenant);
        // 管理端租户管理节点生成的token
        baseParam.setClientToken(token);

        baseParam.setSource(ApplicationConsts.APPLICATION_ID);
        // 租户隔离
        if (!StringUtils.isEmpty(tenantId)) {
            baseParam.setTenantLimitId(tenantId);
        }
        return BpmRests.getBpmRest(baseParam);

    }

}
